﻿using Commonality.ReturnView;
using SqlSugar;
using System.Linq.Expressions;

namespace IService
{
    /// <summary>
    /// 公共接口
    /// </summary>
    public interface IBaseService
    {
        #region 通过ID查询实体
        T IFindEntityForID<T>(int id) where T : class;
        Task<T> IFindEntityForIDAsync<T>(int id) where T : class;
        #endregion
        #region 通过条件查询实体

        Task<List<T>> FindQueryForWhere<T>(Expression<Func<T, bool>> expression) where T :class;

        #endregion
        #region 分页
        PagingData<T> QueryPage<T>(Expression<Func<T, bool>> funcWhere, int pageSize, int pageIndex, Expression<Func<T, object>> funcOrderby, bool isAsc = true) where T : class;
        #endregion
        #region Add

        /// <summary>
        /// 新增数据-同步版本
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        int Insert<T>(T t) where T : class, new();

        /// <summary>
        /// 新增数据-异步版本
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        Task<T> InsertAsync<T>(T t) where T : class, new();

        /// <summary>
        /// 批量新增
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tList"></param>
        /// <returns></returns>
        Task<bool> InsertList<T>(List<T> tList) where T : class, new();
        #endregion


        #region Update
        /// <summary>
        /// 更新数据，即时Commit
        /// </summary>
        /// <param name="t"></param>
        void Update<T>(T t) where T : class, new();


        /// <summary>
        /// 更新数据，异步版本
        /// </summary>
        /// <param name="t"></param>
        Task UpdateAsync<T>(T t) where T : class, new();

        /// <summary>
        /// 更新数据，即时Commit
        /// </summary>
        /// <param name="tList"></param>
        void Update<T>(List<T> tList) where T : class, new();

        int UpdateableFilter<T>(T t, Expression<Func<T, object>> upColu, Expression<Func<T, bool>> wherCol) where T : class, new();
        #endregion


            #region Delete
        /// <summary>
        /// 根据主键删除数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pId"></param>
        /// <returns></returns>
        bool Delete<T>(int pId) where T : class, new();

        /// <summary>
        /// 根据主键删除数据--异步版本
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pId"></param>
        /// <returns></returns>
        Task<bool> DeleteAsync<T>(int pId) where T : class, new();

        /// <su+mary>
        /// 删除数据，即时Commit
        /// </summary>
        /// <param name="t"></param>
        void Delete<T>(T t) where T : class, new();

        /// <summary>
        /// 删除数据，即时Commit
        /// </summary>
        /// <param name="tList"></param>
        void Delete<T>(List<T> tList) where T : class, new();
        #endregion


        #region Other

        /// <summary>
        /// 执行sql 返回集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <returns></returns>
        ISugarQueryable<T> ExcuteQuery<T>(string sql) where T : class, new();

        #endregion
    }
}
